//
//  LeftViewController.m
//  happyHealthyWalk
//
//  Created by newhuidong on 16/2/19.
//  Copyright © 2016年 HuiDong. All rights reserved.
//

#import "LeftViewController.h"
#import "Header.h"
#import "LoginViewController.h"
#import "UserInfoViewController.h"
@interface LeftViewController ()<UITableViewDataSource,UITableViewDelegate,UIGestureRecognizerDelegate>
@property (weak, nonatomic) IBOutlet UIView *bg_view;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIImageView *headImage;
@property(nonatomic,strong)UIViewController * mainVC;

@property (weak, nonatomic) IBOutlet UILabel *name_label;

@property(nonatomic,strong)NSArray * dataArr;
@property(nonatomic,strong)NSArray * imageArr;

@end

@implementation LeftViewController
-(void)viewDidLoad{
    [super viewDidLoad];
    self.headImage.layer.cornerRadius=40;
    self.headImage.layer.masksToBounds=YES;
    self.bg_view.backgroundColor=[UIColor colorWithRed:40/255.0f green:199/255.0f blue:172/255.0f alpha:1];
    self.headImage.userInteractionEnabled=YES;
    
    UITapGestureRecognizer * tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    
    [self.headImage addGestureRecognizer:tap];
    
    _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    _dataArr=@[@"健康里程",@"康复嘉奖",@"我的投稿",@"消息中心",@"邀请好友",@"我的亲友团",@"更多",@"退出登录"];
 _imageArr=@[@"myWay",@"prisent",@"tougao",@"message",@"friends",@"family",@"more",@"exit"];
    
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.backgroundColor=[UIColor clearColor];
    
}
- (void)tap:(id)sender {
    
    UIStoryboard * story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
    LoginViewController* login=[story instantiateViewControllerWithIdentifier:@"LoginViewController"];
    
    if ([self.name_label.text isEqualToString:@"未登录"]) {
        
        
        UINavigationController * nav=[[UINavigationController alloc]initWithRootViewController:login];
        [self presentViewController:nav animated:YES completion:nil];

    }else{
        
        UserInfoViewController * user=[[UserInfoViewController alloc]init];


        UINavigationController * anv=[[UINavigationController alloc]initWithRootViewController:user];
        
        [self presentViewController:anv animated:YES completion:nil];
        
        NSLog(@"进入个人中心");
        
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _dataArr.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * cell_id=@"cell";
    UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:cell_id];
    if (cell==nil) {
        
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_id];
        
    }
    cell.backgroundColor=[UIColor clearColor];
    [cell.textLabel setTextColor:[UIColor whiteColor]];
    [cell.textLabel setText:_dataArr[indexPath.row]];
    cell.imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",_imageArr[indexPath.row]]];
    
    
    
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    return cell;
    
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self deSelectCell];
    if (self.delegate&&[self.delegate respondsToSelector:@selector(LeftViewControllerdidSelectRow:)]) {
        
        NSInteger row =indexPath.row;
        [self.delegate LeftViewControllerdidSelectRow:row];
        
    }
}
- (void)deSelectCell
{
    [self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:NO];
}

@end
